var pageNow=1
SPA_RESOLVE_INIT = function (transition) {
    var html = '<table class="Table_common gradesListTab mt-20">\n' +
        '<thead>\n' +
        '<tr>\n' +
        '<td>id</td>\n' +
        '<td>班级名</td>\n' +
        '<td>人数</td>\n' +
        '<td>操作</td>\n' +
        '</tr>\n' +
        '</thead>\n' +
        '<tbody id="gradeListTabs"></tbody>\n' +
        '</table> ' +
        '    <div class="paging-area-box mt-10 magin-auto">\n' +
        '        <div class="paging-area float-left" id="pagination"></div>\n' +
        '        <span class="pageNum float-right f-14">共<em>0</em>条数据</span>\n' +
        '    </div>';

    html += '<style>\n' +
        ' \n' +
        '.gradesListTab tr td:nth-child(2){\n' +
        'border-left:1px solid #333;\n' +
        'border-right:1px solid #333;\n' +
        '}\n' +
        '.gradesListTab tr td:nth-child(3){\n' +
        'border-right:1px solid #333;\n' +
        '}\n' +
        '\n' +
        '</style>';

    getHref_path();
    $(".menu ul").hide();
    $(".menu ul").eq(1).show();

    document.getElementById("ui-right-content").innerHTML = html;


    gradeListFun(pageNow);
}

function gradeListFun(pageNo) {
    var id = window.document.getElementById("gradeListTabs");

    $.ajax({
        url: get_courseList_interface+'?currentPage='+pageNo,
        type: 'post',
        dataType: 'json',
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        data: {
            currentPage: pageNo
        },
        success: function (data) {
            if (data.code == 200) {
                inner_gradeTbody(data, id, gradeListFun);
            } else {
                $.message(data.msg);
            }
        },
        error: function (error) {
            parent.popMessage("链接超时，请刷新...");
        }
    });
}

function inner_gradeTbody(data, id, func) {
    var page = data.data.num;
    var currentPage = data.data.currentPage;
    var tml = "";
    pageNow=currentPage
    $(".pageNum em").html(page);
    if (page > 0) {
        setPagination(page, currentPage, func);
        var lists = data.data.list;
        $('#pagination').show();
        for (x in lists) {
            tml += "<tr>" +
                '<td>' + lists[x]["courseId"] + '</td>' +
                '<td>' + lists[x]["courseName"] + '</td>' +
                "<td>" + lists[x]["courseStudentNum"] + "</td>" +
                '<td><a href="javascript:;" class="c-009 f-14" onclick="hrefcourseStudentList(this)" data-courseId="' + lists[x]["courseId"] + '" data-courseName="' + lists[x]["courseName"] + '" data-cont="' + lists[x]["newsContent"] + '">学生</a> / ' +
                '<a href="javascript:;" class="c-009 f-14" onclick="hrefupdate(this)" data-courseId="' + lists[x]["courseId"] + '" data-courseName="' + lists[x]["courseName"] + '" data-cont="' + lists[x]["newsContent"] + '">编辑</a> / ' +
                '<a href="javascript:;" class="c-009 f-14" onclick="deleteGradeId(this)" data-courseId="' + lists[x]["courseId"] + '">删除</a></td>' +
                "</tr>";
        }
    } else {
        $('#pagination').hide();
    }
    id.innerHTML = tml;
}

/**删除***/
function deleteGradeId(obj) {
    var courseId = $(obj).attr("data-courseId");
    $.ajax({
        url: delete_course_interface,
        type: 'post',
        dataType: 'json',
        xhrFields: {
            withCredentials: true
        },
        crossDomain: true,
        data: {
            courseId: courseId
        },
        success: function (data) {
            if (data.code == 200) {
                $.message("删除成功");
                gradeListFun(pageNow)
                // $(obj).closest("tr").remove();
            } else {
                parent.popMessage(data.msg);
            }
        },
        error: function (error) {
            $.message("链接超时，请刷新...");
        }
    });
}

function hrefupdate(obj) {
    var courseId =$(obj).attr("data-courseId");
    location.href="?courseId="+courseId.toString()+"#/updatecourse"
}

function hrefcourseStudentList(obj) {
    var courseId =$(obj).attr("data-courseId");
    location.href="?courseId="+courseId.toString()+"#/courseStudentList"
}

